﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Mukhopatro.BusinessLogicLayer;
using Mukhopatro.BusinessEntities;
using Imgalib.Utility;

namespace Mukhopatro.Admin
{
    public partial class edit_content : System.Web.UI.Page
    {
        private Int32 ContentId
        {
            get
            {
                try
                {
                    if (HttpContext.Current.Request.QueryString != null && !string.IsNullOrEmpty(HttpContext.Current.Request.QueryString["id"]))
                    {
                        return Convert.ToInt32(Cryptography.Decrypt(HttpContext.Current.Request.QueryString["id"]));
                    }
                    else
                    {
                        return -1;
                    }
                }
                catch
                {
                    return -1;
                }
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadData();
            }
        }

        private void LoadData()
        {
            CustomerContentBLL bll = new CustomerContentBLL();
            CustomerContent content=bll.GetCustomerContentByContentId(ContentId);
            if (content != null)
            {
                txtTitle.Text = content.CmsTitle;
                CKEditor1.Text=content.CmsContent;
            }
        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            CustomerContentBLL bll = new CustomerContentBLL();
            CustomerContent content = bll.GetCustomerContentByContentId(ContentId);
            if (content != null)
            {
                 content.CmsTitle=txtTitle.Text.Trim();
                 content.CmsContent=CKEditor1.Text;
                 content.DatelastModified = DateTime.Now;
                 bll.UpdateCustomerContent(content);
                 respMessage.SetSuccessMessage("Content Updated Successfully.");
            }
        }

        protected void btnReset_Click(object sender, EventArgs e)
        {

        }
    }
}